package com.example.myapplication.apter;

import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.myapplication.R;
import com.example.myapplication.ShuJu.RoutelistsBean;

import java.util.List;
import java.util.Random;

public class RoutelistsApter extends  RecyclerView.Adapter<RoutelistsApter.MyHolder>{
    private Context context ;
    private List<RoutelistsBean.DataDTO> list;
    private View view;


    public RoutelistsApter(Context context, List<RoutelistsBean.DataDTO> list) {
        this.context = context;
        this.list = list;

    }

    @NonNull
    @Override
    public RoutelistsApter.MyHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        //填充试图
        view = LayoutInflater.from(context).inflate(R.layout.item_routelists,null);
        return new RoutelistsApter.MyHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull RoutelistsApter.MyHolder holder, int position) {

        if(list==null || list.get(position).getLineName()==null){
            return;
        }
        holder.name.setText(list.get(position).getLineName());
        Random random = new Random();
        int color = Color.rgb(random.nextInt(256),random.nextInt(256),random.nextInt(256));
        holder.view.setBackgroundColor(color);

    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    class MyHolder extends RecyclerView.ViewHolder {
        TextView name;
        View  view;

        public MyHolder(@NonNull View itemView) {
            super(itemView);

            name = itemView.findViewById(R.id.name);
            view = itemView.findViewById(R.id.view);

        }
    }
}


